package com.heer.gymnasium.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.heer.gymnasium.R;
import com.heer.gymnasium.util.LoadImageUtil;
import com.heer.model.SitesBean;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by rzw2 on 2017/4/5.
 */

public class HomeSitesAdapter extends ListAdapter<SitesBean.Site> {
    public HomeSitesAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        ViewHolder holder;
        if (view != null) {
            holder = (ViewHolder) view.getTag();
        } else {
            view = mInflater.inflate(R.layout.item_home_fragment_sites, parent, false);
            holder = new ViewHolder(view);
            view.setTag(holder);
        }

        // 设置中划线并加清晰
        holder.tvCost.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);

        SitesBean.Site item = getItem(position);

        holder.tvName.setText(item.getStadiumname());
        Glide.with(mContext).load(LoadImageUtil.getLoadImageUrl(item.getStadiumpic())).placeholder(R.mipmap.ic_launcher).into(holder.imageSite);
        holder.ratingLevel.setRating(item.getStar());

        if (null != item.getTicket()) {
            holder.tvPrice.setText("$" + item.getTicket().getPrice_now() + "/人");
            holder.tvCost.setText(item.getTicket().getPrice());
        } else {
            holder.tvPrice.setText("$0.00/人");
            holder.tvCost.setText("0");
        }

        return view;
    }

    static class ViewHolder {
        @BindView(R.id.image_site)
        ImageView imageSite;
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.rating_level)
        RatingBar ratingLevel;
        @BindView(R.id.tv_price)
        TextView tvPrice;
        @BindView(R.id.tv_cost)
        TextView tvCost;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
